import os
import unittest

#1.testloader
from basic.class18_unitest.test_case import test_login2, test_assert2
from basic.class18_unitest.test_case.test_assert2 import TestAsert2
from basic.class18_unitest.test_case.test_login2 import TestLogin

testloader = unittest.TestLoader()

#2.discover
dirname = os.path.dirname(os.path.abspath(__file__))
report = os.path.join(dirname,"report")
if not os.path.exists(report):
    os.mkdir(report)
#收集测试用例
cases_path = os.path.join(dirname,"test_case")
suit1 = testloader.discover(cases_path)
"""suit = testloader.loadTestsFromModule(test_login2)
suit2 = testloader.loadTestsFromModule(test_assert2)"""

suit = testloader.loadTestsFromTestCase(TestLogin)
suit2 = testloader.loadTestsFromTestCase(TestAsert2)
suit_total = unittest.TestSuite()
suit_total.addTests(suit)
suit_total.addTests(suit2)

file_path = os.path.join(report,"test_report.txt")
with open(file_path,"w",encoding="utf8") as f:
    runner = unittest.TextTestRunner(f)
    runner.run(suit_total)
